import os
from asyncio.windows_events import NULL
import shutil
import cv2

list = os.listdir('./')
lists = []
def see_video(filepath,filesname,filename):
    cap = cv2.VideoCapture(filepath)
    cap.set(cv2.CAP_PROP_POS_FRAMES, 10000)
    # ret, frame = cap.read()
    while (1):
        ret, frame = cap.read()
        res = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5)
        target_Del = NULL
        cv2.imshow('frame', res)
        key = cv2.waitKey(1)
        if  key & 0xFF == ord('q') or ret == False:
            cap.release()
            cv2.destroyAllWindows()
            break
        elif key & 0xFF == ord('d'):
            print("删除或修改视频")
            # target_Del = filename
            cap.release()
            cv2.destroyAllWindows()
            # 修改文件名
            # os.rename(filepath,f"{filepath}==========")
            # 删除文件
            # os.remove(filepath)
            # 删除上级文件夹
            shutil.rmtree(filesname)
            break
        elif key & 0xFF == ord('s'):
            cap.release()
            cv2.destroyAllWindows()
            lists.append(filename,filesname)
            break
        cv2.imshow('frame', res)
    print(filesname,filename,filepath, lists)

if __name__ == '__main__':
    for list_sam in list:
        try:
            test = os.listdir(f'./{list_sam}')
            for te in test:
                mp4 = te.endswith('mp4')
                avi = te.endswith('avi')
                # mp4=False
                # avi=False
                wmv = te.endswith('wmv')
                # print(ls)
                if mp4:
                    # print(f"{te}文件是mp4")
                    see_video(f"./{list_sam}/{te}",list_sam,test)
                elif avi:
                    # print(f"{te}文件是avi")
                    see_video(f"./{list_sam}/{te}",list_sam,test)
                elif wmv:
                    see_video(f"./{list_sam}/{te}",list_sam,test)
        except:
            print(f"{list_sam}不是文件夹")

    print(lists)
